﻿// JScript 文件
/////////////////////////////////////////////////////////////////光路路由图//////////////////////////////////////////
// <Items>
//      <Item id='0' parentid='-1'>
//                 <LY xh='1' adbm='ff' admc='ffmc' adtype='' adkh='' addz='' adglmc='' bdbm='ff' bdmc='ffmc' bdtype='' bdkh='' bddz='' bdglmc='' adzt='' adolt='' bdzt='' pb='' grd=''></LY>
//      </Item>
//      <Item id='1' parentid='0'>
//                 <LY xh='1' adbm='ff' admc='ffmc' adtype='' adkh='' addz='' adglmc='' bdbm='ff' bdmc='ffmc' bdtype='' bdkh='' bddz='' bdglmc='' adzt='' adolt='' bdzt='' pb='' grd=''/>
//      </Item>
//      <Item id='2' parentid='0'>
//                 <LY xh='1' adbm='ff' admc='ffmc' adtype='' adkh='' addz='' adglmc='' bdbm='ff' bdmc='ffmc' bdtype='' bdkh='' bddz='' bdglmc='' adzt='' adolt='' bdzt='' pb='' grd=''/>
//      </Item>
// </Items>                    



var CtnGrLyMap = Class.create();

CtnGrLyMap.prototype =  
{

    initialize: function() 
    {
         var tmp = $A(arguments)
         var options = tmp.shift()
         this.id        = options.id    ? options.id : "_GrLyMap";                    //存放路由图的容器id
         this.zIndex    = options.zIndex ? options.zIndex : 10;                       //层id
         this.l         = options.left  ? parseInt(options.left) : 10;                //相对容器的左边距
         this.t         = options.top   ? parseInt(options.top) : 40;                 //相对容器的顶边距
         
         this.w         = options.w     ? options.w    : 200;                         //设备之间的宽度
         this.h         = options.h     ? options.h : 100;                            //同级路由段的上下间隔
         
         this.readonly  = options.readonly   ? options.readonly : false;              //是否只读
         this.bdrag     = options.bdrag      ? options.bdrag : false;                 //是否能拖动      
      
         this.img_w     = options.img_w   ? parseInt(options.img_w) : 25;              //图片的宽
         this.img_h     = options.img_h   ? parseInt(options.img_h) : 20;              //图片的高
         
         this.lay_h     = options.lay_h   ? parseInt(options.lay_h) : 150;             //图层的默认高度                                                   //层的最大高度
         this.onClick   = null;
         this.onRClick  = null;
         
          
         this.layer     = new Array();                        //[[{id:0,parentid:-1,devinfolist:lyArr,devtypelist:arr,devxhlist:arr}],[{id:1,parentid:0,devinfolist:lyArr,devtypelist:arr,devxhlist:arr}]]
         this.drawPen = new CtnApSvg({
                            SVGEmbed:"SVGEmbed", 
                            id:this.id, 
                            stroked:true,
                            strokeweight: "1px", 
                            zIndex:this.zIndex,
                            OnMouseClick: null
                            });               
         this.createMask();         
            
    }
   
    ,
    getlayerH   : getlayH_GRLY
    ,
    insertInfo  : insertInfo_GRLY
    ,
    Draw        : Draw_GRLY
    ,
    DrawByXml   : DrawByXml_GRLY
    ,
    DrawLy      : DrawLy_GRLY
    ,
    DrawDev     : DrawDev_GRLY
    ,
    DrawLine    : DrawLine_GRLY
    ,
    ConstructLayer :ConstructLayer_GRLY
    ,
    LeftSelPnt  : LeftSelPnt_GRLY
    ,
    LeftSelLin  : LeftSelLin_GRLY
    ,
    RightMenu   : RightMenu_GRLY
    ,
    MouseDown   : MouseDown_GRLY
    ,
    getlayH     : getlayH_GRLY
    ,
    createMask  : createMask_GRLY
    ,
    setMaskWH   : setMaskWH_GRLY
    ,
    clear       :  function()
    {
          for(var  i = 0; i < this.layer.length; i++)
          {
              this.layer.pop();
          }
          
          this.drawPen.clear();
    }
    ,
    moveSpan    : moveSpan_GRLY
    ,
    getlineByFbm: getlineByFbm_GRLY
    ,
    GetMouseObj : GetMouseObj_GRLY
    ,
    moveLine    : moveLine_GRLY
    ,
    mousedown   : mousedown_GRLY
    ,
    mousemove   : mousemove_GRLY
    ,
    mouseup     : mouseup_GRLY
    ,
    mouseclick  : mouseclick_GRLY
    ,
    contextmenu : contextmenu_GRLY
    
}

//移动实体相关的标注信息

function moveSpan_GRLY(dx,dy)
{
    var obj = this.drawPen.getObjById("span_bm" + this.moveent.id)
    this.drawPen.moveObj(obj,dx,dy); 
    
    obj = this.drawPen.getObjById("span_mc" + this.moveent.id)
    this.drawPen.moveObj(obj,dx,dy); 
    
    obj = this.drawPen.getObjById("span_zt" + this.moveent.id)
    this.drawPen.moveObj(obj,dx,dy); 
    
    obj = this.drawPen.getObjById("span_olt" + this.moveent.id)
    this.drawPen.moveObj(obj,dx,dy); 
    
    obj = this.drawPen.getObjById("span_grd" + this.moveent.id)
    this.drawPen.moveObj(obj,dx/2,dy/2); 
    
    obj = this.drawPen.getObjById("span_pb" + this.moveent.id)
    this.drawPen.moveObj(obj,dx/2,dy/2); 
    
    //找到后连接线的span
    var obj = this.drawPen.DrawPen
    for(var i = 0; i < obj.childNodes.length; i++)
    {
        var front_bm = this.drawPen.getObjAtt(obj.childNodes[i],"frontbm");
        if(front_bm == this.moveent.id)
        {
            var tmp = this.drawPen.getObjById("span_pb" + obj.childNodes[i].id.slice(2))
            this.drawPen.moveObj(tmp,dx/2,dy/2); 
            
            tmp = this.drawPen.getObjById("span_grd" + obj.childNodes[i].id.slice(2))
            this.drawPen.moveObj(tmp,dx/2,dy/2); 
        }
    }
    
}

function getlineByFbm_GRLY(bm)
{
    var arr = new Array();
    var obj = this.drawPen.DrawPen
    for(var i = 0; i < obj.childNodes.length; i++)
    {
        var front_bm = this.drawPen.getObjAtt(obj.childNodes[i],"frontbm");
        if(front_bm == bm)
        {
            arr.push(obj.childNodes[i]);
        }
    }
    return arr;
}
//重绘实体相关的线

function moveLine_GRLY(dx,dy)
{
    var p_line = this.drawPen.getObjById("l_" + this.moveent.id);
    var line_arr = this.getlineByFbm(this.moveent.id)
    var flg = false;
    if(p_line)
    {
        line_arr.push(p_line);
        flg = true;
    }
    for(var i = 0; i < line_arr.length; i++)
    {
        p_line = line_arr[i];
        var tmpDot = new Array();
        var vid = p_line.id;
        var frontbm = this.drawPen.getObjAtt(p_line,"frontbm");
        var x1 = this.drawPen.getObjAtt(p_line,"f_x");
        var y1 = this.drawPen.getObjAtt(p_line,"f_y");
        
        var x2 = this.drawPen.getObjAtt(p_line,"s_x");
        var y2 = this.drawPen.getObjAtt(p_line,"s_y");
        if(flg && i == line_arr.length - 1)
        {
           x2 = parseInt(x2) + dx
           y2 = parseInt(y2) + dy 
        }
        else
        {
           x1 = parseInt(x1) + dx
           y1 = parseInt(y1) + dy 
        }
        tmpDot.push(new D_Dot2D(x1,y1,false));
	    tmpDot.push(new D_Dot2D(x2,y2,false));
    	
	    var attarg = {att:[{name:"f_x",val:x1},{name:"f_y",val:y1},{name:"s_x",val:x2},{name:"s_y",val:y2},{name:"frontbm",val:frontbm}]};		
        this.drawPen.Undraw(vid);
        this.drawPen.drawLine({id:vid,dotArr:tmpDot,strokecolor:"blue",strokeweight:"2px"},attarg);
    }
    
}

//得到鼠标当前点击的实体

function GetMouseObj_GRLY(evt)
{
    //要考虑到滚屏时的情况
    
    evt = evt || event;
    this.mouseX = evt.clientX + this.drawPen.DrawPen.scrollLeft;
    this.mouseY = evt.clientY + this.drawPen.DrawPen.scrollTop;
    var obj = null;
    
    var drawobj = this.drawPen.DrawPen
    for(var i = 0; i < drawobj.childNodes.length; i++)
    {
        var tmpobj = drawobj.childNodes[i];
         if(Position.within(tmpobj,this.mouseX,this.mouseY))
         {
             obj = tmpobj;
             break;
         }
    }
    return obj;
}
function contextmenu_GRLY(evt) 
{

    var obj = this.GetMouseObj(evt)
    if(obj != null)
    {
        if(this.onRClick)
        {
           var objtype = this.drawPen.getObjAtt(obj,"objtype");
           this.onRClick(obj,objtype)  //objtype:pnt 点 lin 线
        }
    }
}

function mousedown_GRLY(evt)
{
   var obj = this.GetMouseObj(evt)
   this.moveent = obj;
   
   if(obj != null)
   {
      var objtype = this.drawPen.getObjAtt(obj,"objtype");
      if(objtype == "pnt")
      {
          this.LeftSelPnt(obj)
          this.selenttype = "pnt";
      }
      else
      {
          this.LeftSelLin(obj);
          this.selenttype = "lin";
      }
  
      this.bdown = true;
      //this.moveent = obj;
   }
}

function mousemove_GRLY(evt)
{
   if(this.readonly || !this.bdrag) return;   //如果是只读或者不能拖动实体属性则退出
   if(this.bdown)
   {
       if(this.selenttype == "pnt")
       {
            this.drag  = true;
       }
       else
       {
            return;
       }
       this.bdown = false;
       evt = evt || event;
      
       var y = evt.clientY;
       
       var h = parseInt(this.BgMask.style.height);
       var t = parseInt(this.BgMask.style.top);
       
       this.BgMask.style.cursor = "move";
       
       if(h + t <  y + 90)
       {
           this.BgMask.style.height = y - t + 90;
       }
   }
}

function mouseup_GRLY(evt)
{
    if(this.drag)
    {
        //改变位置
        evt = evt || event;
        var x = evt.clientX;
        var y = evt.clientY;
        var dx = x - this.mouseX;
        var dy = y - this.mouseY;
        
        if(this.moveent)
        {
            this.drawPen.moveObj(this.moveent,dx,dy);
            //重绘实体相关线
            this.moveLine(dx,dy);
            //移动实体相关的标注
            this.moveSpan(dx,dy);
        }
    
        this.drag = false;
    }
   
    this.BgMask.style.cursor = "";
}

function mouseclick_GRLY(evt)
{
      //;
      
      if(this.onClick)
      {
          this.onClick(this.moveent)
      }
}

function LeftSelLin_GRLY(obj)
{
    if(!obj)
    {
       return;
    }  
   
    if(this.preSellin && obj != this.preSellin)
    {
       this.preSellin.setAttribute("strokecolor", "blue");
       this.preSellin.setAttribute("strokeweight", "2px");
       this.preSellin.setAttribute("sel","false");
    }
    var curObj = obj;
   
    var sel = this.drawPen.getObjAtt(curObj,"sel");
   
    if (sel == "false")
    {
       curObj.setAttribute("strokecolor", "red");
       curObj.setAttribute("strokeweight", "3px");
       curObj.setAttribute("sel","true");
       this.preSellin = curObj;
    }
    else
    {
       
       curObj.setAttribute("strokecolor", "blue");
       curObj.setAttribute("strokeweight", "2px");
       curObj.setAttribute("sel","false");
       this.preSellin = null;
    }
}

function LeftSelPnt_GRLY(obj)
{
    if(!obj)
    {
       return;
    }
    var enttype = this.drawPen.getObjAtt(obj.id,"enttype");
    if(this.preSel && obj != this.preSel)
    {
       var perType = this.drawPen.getObjAtt(this.preSel.id,"enttype");
       var vSrc = GetGjsbSrc(parseInt(perType), false)
       this.preSel.src = vSrc;
       this.preSel.setAttribute("sel","false");
    }
    var curObj = obj;
   
    var sel = this.drawPen.getObjAtt(curObj.id,"sel");
   
    if (sel == "false")
    {
       var vSrc = GetGjsbSrc(parseInt(enttype), true)
       curObj.src = vSrc;
      
       this.preSel = curObj;
       curObj.setAttribute("sel","true");
    }
    else
    {
       var vSrc = GetGjsbSrc(parseInt(enttype), false)
       curObj.src = vSrc;
       curObj.setAttribute("sel","false");
    }
}

// 重置遮盖的高

function setMaskWH_GRLY()
{
    this.BgMask.style.height  = (this.t + this.lay_h + 20) + "px";
}

//创建遮盖，遮盖的宽设为100%

function createMask_GRLY()
{
    var str = "<img id='Grly_img'"
            + " galleryimg='no' src='../Images/Null.gif' style=\"z-index: "+(this.zIndex + 10)+";"
            + "filter: 'progid:DXImageTransform.Microsoft.Fade(duration=0.5)';position:absolute; left: "
            + Position.positionedOffset(this.drawPen.DrawPen)[0] +"; top:"
            + Position.positionedOffset(this.drawPen.DrawPen)[1] +"; height:"
            + (this.t + this.lay_h + 50 + 22)+"px; width: 100%;\"/>"
            
     //this.drawPen.DrawPen.insertAdjacentHTML("beforeEnd",str);
     
     var insertbefore = new Insertion.Before(this.drawPen.DrawPen,str);
    //document.body.insertAdjacentHTML("beforeEnd",str);   position:absolute;
    //shape.style.backgroundColor = "#003399";
    this.BgMask = $("Grly_img");
    if(!this.readonly)
    {
        this.BgMask.onmousemove = this.mousemove.bind(this);
        this.BgMask.onmousedown = this.mousedown.bind(this);
        this.BgMask.onmouseup = this.mouseup.bind(this);
        this.BgMask.onclick = this.mouseclick.bind(this);
        this.BgMask.oncontextmenu = this.contextmenu.bind(this);
    }
    
    document.body.ondragstart= function (){return false;}                  //屏蔽鼠标拖动事件
}

//得到图层的最大高度


function getlayH_GRLY()
{
    
    for(var i = 1; i < this.layer.length; i++)
    {
        if((this.layer[i].length - 1) * this.h > this.lay_h && this.layer[i].length > 1)
        {
            this.lay_h = (this.layer[i].length - 1) * this.h;
        }
    }
}


///////////////////插入层节点值：下一步继续插入，或者画路由图（this.draw()） 注：第一次插入前清空（this.clear()）///////////////////////
///说明：一般只显示单层路由图（如：普通光路或者配置过程中的），插值时参数layer,id,parentid可不给值。
///devinfolist 值的存储:[{bm:"bm",mc:"mc",zt:"gjjx",...},{bm:"bm",mc:"mc",zt:"gjjx",...}]
///devtypelist 值的存储:[1,1,2,2,3,3....]
///devxhlist   值的存储:[1,1,2,2,3,3....]


function insertInfo_GRLY()
{
    var tmp = $A(arguments)
    var options = tmp.shift()
    
    var layer       = options.layer       ? parseInt(options.layer)    : 0;               //插入的层次，默认为第0层
    var devinfolist = options.devinfolist ? options.devinfolist        : new Array();     //插入设备信息列表
    //var devtypelist = options.devtypelist ? options.devtypelist        : new Array();     //插入设备类型列表
    //var devxhlist   = options.devxhlist   ? options.devxhlist          : new Array();     //插入设备序号列表
    var id          = options.id          ? parseInt(options.id)       : 0;               //插入节点id
    var parentid    = options.parentid    ? parseInt(options.parentid) : -1;              //插入父节点id
    
    var tmpArr = new Array();
   
    var obj = {};
    obj.id = id;
    obj.parentid = parentid;
    
    obj.devinfolist = devinfolist;
    //obj.devtypelist = devtypelist;
    //obj.lyxhlist    = devxhlist;
    tmpArr.push(obj);
    if(this.layer[layer])
    {
        this.layer[layer] = this.layer[layer].concat(tmpArr);
    }
    else
    {
        this.layer[layer] = tmpArr;
    }
}
//根据xml画光路路由图

function DrawByXml_GRLY(xml)
{
//    xml = "<Items><Item id='0' parentid='-1' grbm='E0803200001'>"
//        + "<LY xh='0' adbm='XXT.AAAAAA01/ODF001' admc='青青家园四期接入网机房ODF001' adtype='1' adkh='4' addz='5' bdbm='XXT.HJLJ0/OBD000002' bdmc='' bdtype='9' bdkh='' bddz='0' bdolt='' bdzt='XXT.HJLJ0/GJ017' pb='' grd='E0803200001'/></Item>"
//        +"<Item id='1' parentid='0' grbm='E0803200001-1'><LY xh='0' adbm='XXT.HJLJ0/OBD000002' admc='' adtype='9' adkh='' addz='1' bdbm='XXT.HJLJ0/ONU0000001' bdmc='三羊渔网厂用户机房光终端盒' bdtype='10' bdkh='' bddz='1' bdolt='' bdzt='' pb='1/2' grd='E0803200001-1'/></Item>"
//        +"<Item id='2' parentid='0' grbm='E0803200001-2'><LY xh='0' adbm='XXT.HJLJ0/OBD000002' admc='' adtype='9' adkh='' addz='2' bdbm='XXT.HJLJ0/ONU0000002' bdmc='三羊伞厂二分厂用户机房光终端盒' bdtype='10' bdkh='' bddz='1' bdolt='' bdzt='' pb='2/2' grd='E0803200001-2'/></Item>"
//        +"</Items>";



     this.clear();
     var XmlDoc = CtnXML.getXmlDoc();
     
     var tmpArr = new Array();
     if (xml.indexOf("<?xml") == -1)
    {
        xml = "<?xml version='1.0' encoding='gb2312' ?> " + xml;
    }
    try
    {
        XmlDoc.loadXML(xml);
    }
    catch (e)
    {
        CtnDlg.msg("xml数据不符合规范！");
        return false;
    }
     var nodes = XmlDoc.selectNodes('Items/Item');
     for( var i = 0; i < nodes.length; i++)
     {
         var devinfoArr = new Array()
         var devtypeArr = new Array()
         var xhArr = new Array()
         var tmpXh = -1;
         var obj = {}
         obj.id = $XML(nodes[i],"id");
         obj.parentid = $XML(nodes[i],"parentid");
         var lyNodes = nodes[i].selectNodes('LY')
         for(var j = 0; j < lyNodes.length; j++)
         {
             var xh = parseInt($XML(lyNodes[j],"xh"));
             if(xh != tmpXh)
             {
                   var tmpbjmp = (j > 0 && $XML(lyNodes[j],"adbm") != $XML(lyNodes[j - 1],"bdbm")) ? true : false;
                   devinfoArr.push({devtype:$XML(lyNodes[j],"adtype"),bjmp:tmpbjmp,bm:$XML(lyNodes[j],"adbm"),mc:$XML(lyNodes[j],"admc"),zt:$XML(lyNodes[j],"adzt"),olt:$XML(lyNodes[j],"adolt")})
                   devinfoArr.push({devtype:$XML(lyNodes[j],"bdtype"),bjmp:false,bm:$XML(lyNodes[j],"bdbm"),mc:$XML(lyNodes[j],"bdmc"),zt:$XML(lyNodes[j],"bdzt"),olt:$XML(lyNodes[j],"bdolt"),pb:$XML(lyNodes[j],"pb"),grd:$XML(lyNodes[j],"grd")})
                   
                   //devtypeArr.push($XML(lyNodes[j],"adtype"))
                   //devtypeArr.push($XML(lyNodes[j],"bdtype"))
                   
                   //xhArr.push(xh)
                   //xhArr.push(xh)
             }
             tmpXh = xh;
         }
         obj.devinfolist = devinfoArr;
         //obj.devtypelist = devtypeArr;
         //obj.lyxhlist    = xhArr;
         tmpArr.push(obj);
     }
     //构造层存储结构
     
     this.ConstructLayer(tmpArr);
     
     //画路由图
     
     this.Draw();
}

//构造各层的值

function ConstructLayer_GRLY(tmpArr)
{
   this.layer[0] = GetLayerElem(tmpArr,-1);
   
   for(var i =  0; i < this.layer.length; i++)
   {
        
        for(var j =0; j < this.layer[i].length; j++)
        {
            var tmp = GetLayerElem(tmpArr,this.layer[i][j].id);
            if(tmp.length > 0)
            {
                if(j == 0 || !this.layer[i+1])
                {
                    this.layer[i+1] = tmp;
                }
                else
                {
                    this.layer[i+1] = this.layer[i+1].concat(tmp);
                }
            }
        }
   }
}

//得到当前层的所有元素

function GetLayerElem(tmpArr,parentid)
{
     var retArr = new Array();
     for(var i = 0; i < tmpArr.length; i++)
     {
         if(tmpArr[i].parentid == parentid)
         {
             retArr.push(tmpArr[i])
         }
     }
     return retArr;
}

//画路由图，画图之前必须先构造好层结构值this.layer

function Draw_GRLY()
{
    var w = 0;
    var t = 0;
    
    try
    {
        this.getlayH();
        for(var i = 0; i < this.layer.length; i++)
        {
             var vN  = this.layer[i].length;
             var h = 0;
             if(vN > 1)h = this.lay_h/(vN - 1);
             
             var tmpw = w;
             for(var j = 0; j < vN; j++)
             {
                  //画连接线。连接该级到其父级
                  if(i > 0)
                  {
                      var line_l = this.l + tmpw - this.w + this.img_w;                          //线的起始left；
                      
                      var parentid = this.layer[i][j].parentid;
                      //找到父节点的位置
                      for(var n = 0; n < this.layer[i-1].length;n++)
                      {
                          if(this.layer[i-1][n].id == parentid)
                          {
                              tmpw = this.layer[i-1][n].w
                              break;
                          }
                      }
                      var line_t = this.t + this.lay_h/2;
                     
                      
                      if(this.layer[i-1].length > 1)
                      {
                           line_t = this.t + this.lay_h/(this.layer[i-1].length - 1) * n;   //线的起始高；
                      }
                      
                      if(vN == 1)
                      {
                          w = this.DrawLy((this.l + tmpw),(this.t + this.lay_h/2),this.layer[i][j],line_t);
                      }
                      else
                      {
                          w = this.DrawLy((this.l + tmpw),(this.t + j*h),this.layer[i][j],line_t);
                      } 
                      
                  }
                  else
                  {
                       w = this.DrawLy((this.l + tmpw),(this.t + this.lay_h/2),this.layer[i][j]);
                       
                  }
                  this.layer[i][j].w = w;   //记录父亲的尾端x,当前x方向从开始到现在的偏移量
                 
             }
        }
        this.setMaskWH();
     }
     catch(e)
     {
         CtnDlg.msg(e.description)
     }
}

//pre_t :上级光路段的最后一个设备的top

function DrawLy_GRLY(l,t,lyinfo,pre_t)
{
    //var vEnt = lyinfo.devtypelist;    //设备类型信息列表
    var vBm  = lyinfo.devinfolist;    //设备编码信息列表
    //var vXh  = lyinfo.lyxhlist;       //路由序列号信息列表
    
    var vLeft = l;
    var vTop = t;
    var start_t = t;
//    if (vEnt.length == vBm.length && vBm.length == vXh.length)
//    {
        var vTmpXh = 0
        var vTmpBm = ""
        for (var i = 0; i < vBm.length; ++i)
        {
            if (vTmpBm != vBm[i].bm)
            {
                if(i == 0 && pre_t)
                {
                    start_t = pre_t;
                }
                else
                {
	                this.DrawDev(vBm[i], vLeft, vTop)
	                if (i > 0)
	                {
	                    if (vBm[i].bjmp) //vTmpXh == vXh[i]
                        {
                             this.DrawLine(vBm[i], 2, vLeft-(this.w - this.img_w), start_t + this.img_h/2, vLeft, vTop + this.img_h/2,vTmpBm)
                        }
                        else
                        {
                             this.DrawLine(vBm[i], 1, vLeft-(this.w - this.img_w), start_t + this.img_h/2, vLeft, vTop + this.img_h/2,vTmpBm)
                        }
                    }
    	            
	                vLeft = vLeft+this.w
	                start_t = vTop;
	            }
	            vTmpBm = vBm[i].bm
    	    } 
	        //vTmpXh = vXh[i]
        }
        return vLeft - this.l;   // 返回下一次应该画路由段图的距左宽度
//    }
//    else
//    {
//       throw "传入参数有误！画路由时设备与序号的数目应该相等！";
//    }
}

function DrawDev_GRLY(devinfo, l, t)
{
    var vstr = "";
    type = devinfo.devtype;
    var src = GetGjsbSrc(parseInt(type),false);                            //得到设备图标位置
    
    var split = ""
    var span_h = 20;
    
    
    //显示设备的编码
    this.drawPen.drawText({id:"span_bm"+devinfo.bm,x:l, y:t - span_h, text:devinfo.bm})
    if(devinfo.mc)
    {
       //显示设备的名称
       this.drawPen.drawText({id:"span_mc"+devinfo.bm,x:l, y:t - 2*span_h, text:devinfo.mc})
    }
//    if(parseInt(this.graphtype) == enumCtnGrType.enumGr_EPON)
//    {
        //显示EPON的信息
        if(devinfo.zt)
        {
            this.drawPen.drawText({id:"span_zt"+devinfo.bm,x:l, y:t + span_h, text:"载体: " + devinfo.zt})
        }
        //显示olt的信息
        if(devinfo.olt)
        {
            this.drawPen.drawText({id:"span_olt"+devinfo.bm,x:l, y:t + 2*span_h, text:"OLT: " + devinfo.olt})
        }
//    }
   
    if (this.readonly)
    {
        var arg = 
		        {  id:devinfo.bm,x:l, y:t, w:this.img_w,h:this.img_h,href:src
		        }
		          
		this.drawPen.drawImage(arg)
    }
    else
    {
         var vparam = {type:type}
         var arg = 
		        {  id:devinfo.bm,x:l, y:t, w:this.img_w,h:this.img_h,href:src,
		           OnMouseClick:{fun:this.LeftSelPnt.bind(this),param:vparam},
		           OnRightClick:{fun:this.RightMenu.bind(this),param:vparam},
		           OnMouseDown:{fun:this.MouseDown.bind(this)}
		        }
		          
		this.drawPen.drawImage(arg,{att:[{name:"objtype",val:"pnt"},{name:"sel",val:"false"},{name:"enttype",val:type}]})

    }
}
       
function DrawLine_GRLY(devinfo, type, x1, y1, x2, y2,frontbm)
{
    var vstr = ""
    var split = ""
    
//     if(parseInt(this.graphtype) == enumCtnGrType.enumGr_EPON)
//    {
        var vtop = (y1 + y2)/2  - 10
        var vleft = (x1 + x2)/2 - 30 
        //显示EPON的信息
        if(devinfo.grd)
        {
            this.drawPen.drawText({id:"span_grd"+devinfo.bm,x:vleft, y:vtop, text:"光路段: " + devinfo.grd})
        }
        //显示olt的信息
        if(devinfo.pb)
        {
            this.drawPen.drawText({id:"span_pb"+devinfo.bm,x:vleft, y:vtop + 18, text:"端口: " + devinfo.pb})
        }
//    }
    
    var tmpDot = new Array();
    tmpDot.push(new D_Dot2D(parseInt(x1),parseInt(y1),false));
	tmpDot.push(new D_Dot2D(parseInt(x2),parseInt(y2),false));
	
	var attarg = {att:[{name:"sel",val:"false"},{name:"objtype",val:"lin"},{name:"f_x",val:x1},{name:"f_y",val:y1},{name:"s_x",val:x2},{name:"s_y",val:y2},{name:"frontbm",val:frontbm},{name:"endbm",val:devinfo.bm}]};
	var bdash = false;
	if (type == 2) bdash = true;                 //画虚线
			
//    if (this.readonly)
//    {
    
        this.drawPen.drawLine({id:"l_" + devinfo.bm,dotArr:tmpDot,strokecolor:"blue",strokeweight:"2px",bdash:bdash},attarg);
        //vstr += "<v:line id='"+bm+"'from='0,0' to='"+(x2-x1)+", "+(y2-y1)+"' style='position:absolute;left:"+(x1+12)+";top:"+(y1+10)+"' strokecolor='gray'>"
//    }
//    else
//    {
//        this.drawPen.drawLine({id:"l_" + devinfo.bm,dotArr:tmpDot,strokecolor:"blue",strokeweight:"2px",bdash:bdash},attarg);
//        //vstr += "<v:line id='"+bm+"' FxToX='"+(x2-x1)+"' FxToY='"+(y2-y1)+"'  from='0,0' to='"+(x2-x1)+", "+(y2-y1)+"' style='position:absolute;left:"+(x1+12)+";top:"+(y1+10)+"' strokecolor='gray' onclick='javascript:LeftGrLineSel(this)' oncontextmenu='javascript:RightGrLineSel(this)'>"
//    }
//    
}

         
function RightMenu_GRLY(evt,param)
{
   if(parseInt(param.type) == enumCtnOBoxType.enumOBOX_GYHD)
   {
        //查看光用户点的属性
   
   }
}        
function MouseDown_GRLY()
{
      

}





/////////////////////////////////////////////////////////////////局向光纤逻辑图//////////////////////////////////////
//根据跳转次数和起始设施画局向光纤逻辑图
//
//
//                                 
var CtnLogicMap = Class.create();

CtnLogicMap.prototype = 
{

    initialize: function() 
    {
       var tmp = $A(arguments)
       var options = tmp.shift()
       this.zjNum  = options.zjNum ? options.zjNum : 1;                         //跳转次数
       this.zIndex    = options.zIndex ? options.zIndex : 10;     
         
       this.layersArray = new Array();                                          //实体分级存储
       
       this.img_Height    = options.img_Height     ? options.img_Height : 20;       //实体图片高
       this.img_Width     = options.img_Width      ? options.img_Width : 25;         //实体图片宽 
       this.top_Height    = options.top_Height     ? options.top_Height : 70;       //图层上边距
       this.left_width    = options.left_width     ? options.left_width : 50;       //图层左边距
       this.horizen_span  = options.horizen_span   ? options.horizen_span : 150;  //实体之间的水平宽度
       this.vertical_span = options.vertical_span  ? options.vertical_span : 50; //实体之间的垂直高度
       this.span_h        = options.span_h         ? options.span_h : 30;               //标注的高
       //this.bCfg          = options.bCfg           ? options.bCfg : false;                //是否配置光路，否：只是查看逻辑图
       this.name          = options.name           ? options.name : "Logicmap";           //对象名称
       this.grtype        = options.grtype         ? options.grtype : "0";   
       this.qxnum         = options.qxnum          ? options.qxnum : 2; 
       
       this.qsent         = options.qsent          ? options.qsent : "";                 //起始设施
       this.zzent         = options.zzent          ? options.zzent : "";                 //终止设施
       this.qslay         = options.qslay          ? options.qslay : 3;                  //起始设施层
       this.zzlay         = options.zzlay          ? options.zzlay : 3;                  //终止设施层
       this.bcfg          = options.bcfg           ? options.bcfg : 1;    
       this.bcheckTl      = options.bcheckTl       ? options.bcheckTl : false;          //是否通路检查
       this.jmpn_nextly   = 1;               //下一级逻辑图的出图级数
       
       this.m_LyArrayList = new Array();
       this.m_LyArray     = new Array();
       
       
       this.lylist        = new Array();             //当前选则的实体所在的路由列表
       this.m_NodeidArray = new Array();
       this.m_precheck    = "";
       this.parentid      = 0;
       this.m_NodeidArray.push(0);
       
       
       this.XmlDoc = CtnXML.getXmlDoc();
       this.xmlArr = new Array();
       
       this.drawPen = new CtnApSvg({
                            SVGEmbed:"SVGEmbed", 
                            id:"JxgqLogicMap", 
                            stroked:true,
                            strokeweight: "1px", 
                            zIndex:this.zIndex,
                            OnMouseClick: null
                            });   
        
    }
    ,
    showLogicMap   : showLogicMap_MAP                    //根据xml显示逻辑图
    , 
    drawGraph      : drawGraph_MAP                       //画局向光纤逻辑图
    ,
    drawLine       : drawLine_MAP                        //根据前后节点的关系画线
    ,
    LeftSelPnt     : LeftSelPnt_MAP                      //实体的左键响应消息
    ,
    RightSelPnt    : RightSelPnt_MAP                     //实体的右键响应消息
    ,
    showRightMenu  : showRightMenu_MAP                   //构造右键采单
    ,
    DispSbBm       : DispSbBm_MAP                        //显示设备编码
    ,
    HidSbBm        : HidSbBm_MAP                         //隐藏设备编码
    ,
    IsShowFirstEnt : IsShowFirstEnt_MAP                  //第一个实体是否可配置光路，只有当改设备有pos设备的时候才有用
    ,
    dispLy         : dispLy_MAP                          //显示路由情况列表
    ,
    GetNextLy      : GetNextLy_MAP                       //构造下一级地图
    ,
    PosToGyhd      : PosToGyhd_MAP                       //从pos配置光路到光用户点
    ,
    GetLyListById  : GetLyListById_MAP
    ,
    ConstructLyByZt: ConstructLyByZt_MAP
    ,
    GetLyByLyMpos1 : GetLyByLyMpos1_MAP
    ,
    GetLyArrayList : GetLyArrayList_MAP
    ,
    IshasPos       : IshasPos_MAP
    ,
   
    check          : check_MAP
    ,
    GetBmListByLy  : GetBmListByLy_MAP
    ,
    LookLyDetial   : LookLyDetial_MAP
    ,
    BackPreLevel   : BackPreLevel_MAP
    ,
    FlashLy        : FlashLy_MAP
    ,
    GetSelRes      : GetSelRes_MAP
    ,
    GetNodeById    : GetNodeById_MAP
    ,
    GetLyNodeById  : GetLyNodeById_MAP
    ,
    GetNodeByChild : GetNodeByChild_MAP
    ,
    clearLayer  : function()                             //清空图层
    {
        while (this.layersArray.length > 0)
	    {
		    this.layersArray.pop()
	    }
	    this.drawPen.clear();
	    
	    this.m_precheck    = "";
    }
    ,
    reset       : function(){while(this.xmlArr.length > 0){this.xmlArr.pop();}}

}

function showLogicMap_MAP(xml)
{
    var i = 0;
    var j = 0;
    this.XmlDoc.loadXML(xml);
	this.clearLayer();
	
	var nodes = this.XmlDoc.selectNodes('Items/Item')

	for(i = 0; i <= parseInt(this.zjNum); i++)
	{
		var nodeArray = new Array()
		this.layersArray.push(nodeArray)
	}
	for(j = 0; j < nodes.length; j++)
	{	
		var Layer = nodes[j].selectNodes('Layer')
		var LayerVal = parseInt($XML(Layer[0]));
		var ID = nodes[j].selectNodes('ID')
		var IDVal = $XML(ID[0])
		var nodeArray = this.layersArray[LayerVal]
		nodeArray.push(IDVal)
	}
	this.drawGraph();
}

// 由id得到节点

function GetNodeById_MAP(vID)
{
    var nodes = this.XmlDoc.selectNodes('Items/Item')
    var node = null;
    for(j = 0; j < nodes.length; j++)
	{	
		var ID = nodes[j].selectNodes('ID')
		var IDVal = $XML(ID[0])
		if(parseInt(vID) == parseInt(IDVal))
		{
		   node = nodes[j];
		   break;
		}
	}
	return node;
}
//画逻辑图
function drawGraph_MAP()
{
	var maxNodeNum = 0    ;   //得到最大一层的节点个数
	for(var i = 0; i <= this.zjNum; i++)
	{
		if(maxNodeNum <= this.layersArray[i].length )
		{
			maxNodeNum = this.layersArray[i].length
		}	
	}	
	var total_Height = maxNodeNum * this.img_Height + (maxNodeNum - 1) * this.vertical_span + this.img_Height * 2;
	var nodes = this.XmlDoc.selectNodes('Items/Item')
	var strInfo = ""
	for(var i = 0; i < this.layersArray.length; i++)
	{
	    var nodeArray = this.layersArray[i]
		var nodeNum = nodeArray.length
		for(var j = 0; j < nodeNum; j++)
		{
			var top = this.top_Height + (j + 1) * (total_Height - this.img_Height * nodeNum) / (nodeNum + 1) + j * this.img_Height;
			var left = this.left_width + (this.horizen_span + this.img_Width) * i;
			var Font_top = top - 15;
			var Font_left = left;
			var X = left + this.img_Width / 2;
			var Y = top + this.img_Height / 2;
			var IDval = nodeArray[j]
			var node = this.GetNodeById(IDval);//nodes[IDval]	
			var Position = node.selectNodes('Position')
			if(CtnBrowser.FF)
			{
			    Position[0].textContent =  X + "|" + Y;
			}
			else
			{
		        Position[0].text =  X + "|" + Y;
		    }
			var ID = node.selectNodes('ID')
		    var IDVal = $XML(ID[0])	
			var MC = node.selectNodes('MC')
		    var MCVal = $XML(MC[0]);
		    
		    var BM = node.selectNodes('BM')
		    var BMVal = $XML(BM[0]);

		    var EnumType = node.selectNodes('EnumType')
		    var EnumTypeVal = $XML(EnumType[0]);
		   
		    var vMBmVal = node.selectNodes('MBmList')
		    
		    var vSjGrdBmVal = node.selectNodes('GrdList')
		    
		    var vSrc = GetGjsbSrc(parseInt(EnumTypeVal), false)
		    
		    var vparam = {type:EnumTypeVal}
		    arg = 
		        {  id:IDVal,zIndex:this.zIndex + 1 ,x:left, y:top, w:this.img_Width,h:this.img_Height,href:vSrc,
		           OnMouseClick:{fun:this.LeftSelPnt.bind(this),param:vparam},
		           OnRightClick:{fun:this.RightSelPnt.bind(this),param:vparam}
		        }
		          
		    this.drawPen.drawImage(arg,{att:[{name:"sel",val:"false"},{name:"enttype",val:EnumTypeVal}]})
		    this.drawPen.drawText({id:"span"+IDVal,zIndex:this.zIndex + 3,x:Font_left, y:Font_top, text:MCVal},{att:[{name:"BM",val:BMVal}]})
		    
		    //strInfo += " <v:rect id='span" + IDVal + "' style='position: absolute; top:"+Font_top+"; left:"+Font_left+";width="+vMcWidth+";height=30;Z-INDEX: 1;' strokecolor='white'>"+MCVal+"</v:rect>";
			//strInfo += " <v:image id='" + IDVal + "' src='"+vSrc+"' alt='"+MCVal+"' style='position:absolute;top:"+top+";left:"+left+";width:25;height:20;Z-INDEX: 3' onclick='javascript:LeftSelPnt(this, "+vEnt+")' oncontextmenu='javascript:RightSelPnt(this , "+vEnt+")' />";
			if(vMBmVal[0].childNodes.length > 0)
			{
			    this.drawPen.drawText({id:"spanPos"+IDVal,zIndex:this.zIndex + 3,x:(left+26), y:top, text:"<font color = red>(POS)</font>"})
			    //strInfo += " <v:rect id='spanPos" + IDVal + "' style='position: absolute; top:"+top+"; left:"+(left+26)+";width=50;height=20;Z-INDEX: 1;' strokecolor='white'><font color = red>(POS)</font></v:rect>";
			}
			if(vSjGrdBmVal[0].childNodes.length > 0)
			{
			    this.drawPen.drawText({id:"spanGrd"+IDVal,zIndex:this.zIndex + 3,x:left, y:(top + 20), text:"<font color = red>存在光路段</font>"})
			    //strInfo += " <v:rect id='spanGrd" + IDVal + "' style='position: absolute; top:"+(top + 20)+"; left:"+left+";width=90;height=20;Z-INDEX: 1;' strokecolor='white'><font color = red>存在光路段</font></v:rect>";
			}
			strInfo = this.drawLine(i, IDval, X, Y,node,strInfo);
			
		}
	}
	return strInfo								
}

function drawLine_MAP(i, IDval, X, Y, node, strInfo)
{
    var PreNodeList = node.selectNodes('PreNodeList')
	var PreNodeListVal = PreNodeList[0].text
	
	if(PreNodeListVal.length == 0 || PreNodeListVal == "-1")
	     return;
	var split = PreNodeListVal.split('|')
	if(i >= 1)  
	{			
		for(m = 0; m < split.length; m++)
		{
			var ID = split[m]
			//var nodes = this.XmlDoc.selectNodes('Items/Item')
			
			var tmpnode = this.GetNodeById(ID);
			var Position = tmpnode.selectNodes('Position')
		    var PositionVal = $XML(Position[0]);
		    var val = PositionVal.split('|')
			var prex = val[0];  
			var prey = val[1];
			var LineID = ID + "-" + IDval
			var tmpDot = new Array();
			tmpDot.push(new D_Dot2D(parseInt(prex),parseInt(prey),false));
			tmpDot.push(new D_Dot2D(parseInt(X-this.span_h),parseInt(Y),false));
			tmpDot.push(new D_Dot2D(parseInt(X),parseInt(Y),false));
			this.drawPen.drawShape({id:LineID,fill:"white",dotArr:tmpDot,strokecolor:"blue",strokeweight:"1.75px", filled: false});
	     }	                         
	} 
	return strInfo
}


function LeftSelPnt_MAP(evt,param)
{
   //CancelSel()
   var enttype = param.type;
   if(this.preSel)
   {
       var perType = this.drawPen.getObjAtt(this.preSel.id,"enttype");
       var vSrc = GetGjsbSrc(parseInt(perType), false)
       this.preSel.src = vSrc;
       this.preSel.setAttribute("sel","false");
   }
   var curObj = evt ? evt.target : event.srcElement;
   
   var sel = this.drawPen.getObjAtt(curObj.id,"sel");
   
   if (sel == "false")
   {
       var vSrc = GetGjsbSrc(parseInt(enttype), true)
       curObj.src = vSrc;
      
       this.preSel = curObj;
       curObj.setAttribute("sel","true");
    }
   else
   {
       var vSrc = GetGjsbSrc(parseInt(enttype), false)
       curObj.src = vSrc;
       curObj.setAttribute("sel","false");
   }
}

function RightSelPnt_MAP(evt)
{
    try
    {
        var curObj = evt ? evt.target : event.srcElement;
        var sel = this.drawPen.getObjAtt(curObj.id,"sel");
        
        if (sel == "true")
        {
            this.showRightMenu(evt,curObj)
        }
     }
    catch(e)
    {
    } 
}

///右键菜单

function showRightMenu_MAP(evt,curObj)
{
     this.mc = new CtnMenuCtrl(this.name + ".mc");
     
     if(this.bcheckTl)
     {
        var node = this.GetNodeById(curObj.id);
        var bm = $XML(node.selectNodes("BM")[0]);
        if(bm == this.zzent)
        {
           this.mc.addEvent("查看路由", this.name + ".dispLy('"+curObj.id+"')");
           this.mc.show(evt);
        }
        return
     }
     
     var bShowFirEnt = this.IsShowFirstEnt(curObj.id)
     
      if(bShowFirEnt && this.bcfg)
	   {
	        this.mc.addEvent("查看路由", this.name + ".dispLy('"+curObj.id+"')");
	   }
	   this.mc.addEvent("下一级逻辑图", this.name + ".GetNextLy('"+curObj.id+"')");
	   
	   
	   var vData = document.getElementById("spanPos" + curObj.id);
	   if(vData && this.bcfg)
	   {
	      
	      this.mc.addEvent("pos用户配置", this.name + ".PosToGyhd('"+curObj.id+"')");
	   }
	  this.mc.show(evt);
}   
    
function DispSbBm_MAP()
{
   var _drawPen = this.drawPen.DrawPen
   var childCount = _drawPen.childNodes.length;
   
   for(var i=0; i < childCount; i++)
   {
        var childObj = _drawPen.childNodes.item(i);
        if(childObj.id.indexOf("span") != -1)
        {
           var tmpBm = this.drawPen.getObjAtt(childObj.id,"BM");
           if(tmpBm.length > 0)
           {
              if(this.drawPen.svgDoc)
              {
                  //svg情况的处理
                  childObj.removeChild(childObj.childNodes[0])
              }
              else
              {
                  var vl = childObj.style.left
                  var vt = parseInt(childObj.style.top) - 16;
                  var text = tmpBm;
                  this.drawPen.drawText({id:"spanBm"+i,x:vl, y:vt, text:text})
              }
           }
        }
   }
}


function HidSbBm_MAP()
{
   var _drawPen = this.drawPen.DrawPen
   var childCount = _drawPen.childNodes.length;
   
   for(var i=childCount - 1; i >= 0; i--)
   {
        var childObj = _drawPen.childNodes.item(i);
        if(childObj.id.indexOf("spanBm") != -1)
        {
           this.drawPen.Undraw(childObj.id);
        }
   }
}



 function IsShowFirstEnt_MAP(id)
 {
      var returnVal = true
      var IDVal = parseInt(id);
      //var nodes = this.XmlDoc.selectNodes('Items/Item')
     //LyNodes = nodes[IDVal].selectNodes('LyList/Ly')	
     this.GetLyNodeById(IDVal);
     
     if(this.lylist.length == 1)
     {
         var Ly = this.lylist[0];
        
         if(Ly.length == 1)
         {
            
             var vMBmList = Ly[0].selectNodes('MBmList')
		    
		     if(vMBmList[0].length == 0)
		     {
		         returnVal = false
		     }
         }
     }
     
      return returnVal;
 }

 function UpdateLyArr(vLyArray)
 {
     var LyNum = vLyArray.length
	  for(var n = 0;n < LyNum;n++)
	  {
	                    
          var vRoot = vLyArray[n].split('+')
          vLyArray[n] = ""
          for(var x = 0; x < vRoot.length; x++)
          {	
            
	          var vDatas = vRoot[x].split('|')
	          if(vDatas[0].indexOf("/ODF") == -1 && vDatas[1].indexOf("/MPOS") != -1)
	          {
	               var strTempLy = vDatas[0] + "|";
	               for(var m= 1;m < vDatas.length; m++)
	               {
	                  vLyArray[n] += vDatas[m]
	                  strTempLy += vDatas[m]
	                  if(m < vDatas.length - 1)
	                  {
	                      vLyArray[n] += "|"
	                      strTempLy += "|"
	                  }
	               }
	               vLyArray[n] += "+" + strTempLy;
	          }
	          else
	          {
	             for(var m= 0;m < vDatas.length; m++)
	               {
	                  vLyArray[n] += vDatas[m]
	                  if(m < vDatas.length - 1)
	                  {
	                      vLyArray[n] += "|"
	                  }
	               }
	          }
	         if(x < vRoot.length - 1)
	          {
	              vLyArray[n] += "+"
	          }
	       }
 
	  }
 }

 //显示路由列表

 function dispLy_MAP(id)
 {
 
     var bGetMinVal = false;
     var html = "<table>";
 
	  this.GetLyListById(id);   //根据id得到路由列表   
	  
	  if(this.objListLy.length == 0)
	  {
	      return;
	  }
	   //如果为设备层的路由 则需要取光路长度和最小纤芯数
	  if(parseInt(this.enttype) == enumCtnEntLay.enumOBOX_SS)
	  {
	       
	       //bGetMinVal = true;
	       this.lyMinValList = new Array();//{cd:,qx:}
	  }
	  //构造html
	  for(var i = 0; i < this.objListLy.length; i++)
	  {
	     var aList = this.objListLy[i];
	     for(var k = 0; k < aList.length; k++)
	     { 
	         html += "<tr>"
	               + "<td><input type='checkbox' style='width:20px;' onclick='top.Grdlg.wnd."+this.name+".check("
	               + i +"," + k + ",this)'/></td>";
             html += "<td>";
             var ly = aList[k];
             for(var j = 0; j < ly.length; j++)
             {
                  var bm = ly[j].bm;
                  var type =  ly[j].type;
                  var typemc = GetGjsbTypeVal(parseInt(type)); 
                  var enttype = GetEnttype(type);
                 
                  html += typemc + ":" 
                      + "<a href='#LKFD?' onclick=\"top.ExecuteATool(top.m_vt.FUN_ATTBM,["
                      + enttype.maj + "," + enttype.min + ",'" + bm + "',null,null,null])"
                      +"\">" + bm + "</a>";
                      
                  if(j < ly.length - 1)
                  {
                      html += "<font color='red'>===></font>";
                  }  
             }
             html += "</td>";
	          if(bGetMinVal)
	         {
	              html += "<td>";
	              html += "长度:" + this.lyMinValList[i][k].cd + "最少纤芯:" + this.lyMinValList[i][k].qx;
	              html += "</td>";
	          }  
	          html += "</tr>";
	       }
	  }
	  html += "</table>";
	     /*   
	        //如果为设备层的路由 则需要取光路长度和最小纤芯数
	        if(parseInt(this.enttype) == enumCtnEntLay.enumOBOX_SS)
	        {
	            var strLy = ""
	            for (var i = 0; i < vLyArray.length; i++)
	            {
	                var splits = vLyArray[i].split('+')
	                for(var j = 0; j < splits.length; j++)
	                {
	                    strLy += splits[j]+ "|" + ""+i+"-"+j+""
	                    if (j < splits.length - 1)
	                    {
	                        strLy += "_";
	                    }
	                }
	                if (i < vLyArray.length - 1)
	                {
	                    strLy += "_";
	                }
	            }
	          	            
	           var serverUrl = "_method=GetLyDetail"
                               + "&LyList=" + escape(strLy);
                               
               var vRes = CtnTrans.getText("/main.ashx?", "post", serverUrl)
	            
	           vStr = this.ShowLyDetail(vRes)
	        }
	        else
	        {
	            var lyxh = 1
	            
	            vStr = "<table cellspacing=0 cellpadding=0 border=1 bgcolor='Gainsboro'><tr class='trrowtitle'><td>选择</td><td>路由序号</td><td>路由概况</td><tr>"
	            for (var i = 0; i < vLyArray.length; ++i)
	            {
	               
	                var splits = vLyArray[i].split('+')
                    for(var j = 0; j < splits.length; j++)
                    {
                        vStr += "<tr>"
                        vStr += "<td><input id="+i+"-"+j+" type=checkbox style='width:20;' onclick='top.Grdlg.wnd."+this.name+".check("+i+",this)'/></td>"   //this.LyIdList[i]
                        vStr += "<td>"+lyxh+"</td>"
                        var vLyList = splits[j].split('|')
                        vStr += "<td>"
    	            
                        for (var l = 0; l < vLyList.length; ++l)
                        {
                            vStr += vLyList[l]
                            if (l < vLyList.length - 1)
                            {   
                                vStr += "<font color='red'>----></font>"
                            }
                        }
    	            
                        vStr += "</td></tr>"
                        lyxh++
                    }
	            }
	            vStr += "</table>"
	         
            }*/
            var bodyWidth = 700;
            
            if(CtnBrowser.IE)
	        {
	            bodyWidth  = document.getElementsByTagName("body")[0].clientWidth - 50;
	        }
	        else if(CtnBrowser.FF)
	        {
	            bodyWidth  = document.documentElement.clientWidth - 50;
	        }
            var params = {
                        
                        title: "光路路由详情列表",
                        bmax: true,
                        bmin:true,
                        width:bodyWidth,
                        bmodal: false,
                        bresize:true,
                        arrbtn: [{text:"查看局向光纤  ", onClick:function(dlg){dlg.wnd.jxmapobj.LookLyDetial(dlg);}},{text:"  关 闭", onClick:function(dlg){dlg.close();}}]
                     }
           
           top.Grdlg = top.CtnDlg.show(html,params);  //LookLyDetial
           top.Grdlg.wnd = window;                    //把当前window对象放到上层，
           window.jxmapobj       = this;
 }

//根据id得到路由节点列表

function GetLyNodeById_MAP(ID)
{
    var node = this.GetNodeById(ID);
    
    this.lylist = new Array();
    
    var ly1 = new Array();
    
    ly1.push(node);
    
    this.lylist.push(ly1);
    this.GetNodeByChild(node,ly1);
    
    for(var i = 0; i < this.lylist.length; i++)
    {
        this.lylist[i].reverse();
    } 
}

//1 : 根据孩子节点得到上层节点  
//2 : 填充返回值

function GetNodeByChild_MAP(node,curArr)
{
    var nodes = this.XmlDoc.selectNodes('Items/Item')
    var pId = $XML(node.selectNodes('PreNodeList')[0])
    
    var tmpArr = new Array();
    tmpArr = tmpArr.concat(curArr);
    
	var pIdlist = pId.split('|');
	for(var i = 0; i < pIdlist.length; i++)
	{
	    var tmpnode = this.GetNodeById(pIdlist[i]);
	    if(i == 0)
	    {
	        curArr.push(tmpnode)
	        if(parseInt(pIdlist[i]) == 0)
	            continue;
	        this.GetNodeByChild(tmpnode,curArr)
	    }
	    else
	    {
	        var ly_arr = new Array();
	        ly_arr = ly_arr.concat(tmpArr);
	        ly_arr.push(tmpnode);
	        this.lylist.push(ly_arr);
	        
	        this.GetNodeByChild(tmpnode,ly_arr)
	    }
	    
	}
}

//根据id得到路由信息列表
// 首先得到节点路由id
//再根据该路由列表得到全部的路由列表（生成的新的路由段都是有OBD的）
function GetLyListById_MAP(Id)
{

    this.GetLyNodeById(parseInt(Id));     //得到该节点所在的路由 上的 节点列表
    
    //构造路由列表
    
    this.objListLy = new Array();
    
    for(var i = 0; i < this.lylist.length; i++)
    {
        var tmpList = new Array();
        var ly = this.lylist[i];
        for(var j = 0; j < ly.length; j++)
        {
           tmpList = pushdevtoly(ly[j],tmpList,j == 0,j == ly.length - 1);
        }
        
        this.objListLy.push(tmpList);
    }
    
}

//把当前设备push到路由列表
// sbnode 设备节点 lylist 路由列表 bEnd 是否为最后一个设备
// 1：如果第一个设备有附属OBD 那么以OBD为起点生成一条新的路由段
// 2：如果中间的设备有附属OBD 那么OBD与该设备要前后连接
// 3：如果最后一个设备有OBD   那么OBD为终点生成一条新的路由段

function pushdevtoly(sbnode,lylist,bFrt,bEnd)
{
     //var bFrt = lylist.length == 0;    //是否为第一个设备
     //var bEnd = lylist.length == l;    //是否为最后一个设备，即当前选择的设备
     
     var ptmpLylist = new Array();      //生成的新的路由段列表
     
    
     var bm      = $XML(sbnode.selectNodes('BM')[0]);     //设备编码
     var EnumType = $XML(sbnode.selectNodes('EnumType')[0]); //设备类型
     var mnodes   = sbnode.selectNodes('MBmList')[0].childNodes;  //当前节点的附属设备
     
     //首先把当前设备存入路由列表 
     if(bFrt)
     {
         var ly = new Array();
         ly.push({bm:bm,type:EnumType});
         lylist.push(ly); 
     }  
     else
     {  
         for(var i = 0; i < lylist.length; i++)
         {
            lylist[i].push({bm:bm,type:EnumType});
         }  
     }  
     
     
     //把附属设备存入路由列表 同时 生成新的路由段 
     for(var i = 0; i < mnodes.length; i++)
     {
         var mnode = $XML(mnodes[i]);
         var tmpLylist = new Array(); 
         
         if(bFrt)  //如果是第一个设备那么 则把OBD存入新列表
         {
             var ly = new Array();
             ly.push({bm:mnode,type:enumCtnOBoxType.enumOBOX_POS});
             ly.push({bm:bm,type:EnumType}); 
             tmpLylist.push(ly); 
         }
         else
         {
             //值拷贝到新的路由列表
             for(var j = 0; j < lylist.length; j++)
             {
                var ly = new Array();
                for(var k = 0; k < lylist[j].length;k++)
                {
                   ly.push(lylist[j][k]);
                }
                tmpLylist.push(ly);
             }   
             
             //生成新的路由列表 
             for(var j = 0; j < lylist.length; j++)
             {
                tmpLylist[j].push({bm:mnode,type:enumCtnOBoxType.enumOBOX_POS});
                if(!bEnd) //如果不是最后一个设备 那么要把设备再加入到路由列表 如: GJ01--> ODF01--> OBD01 --> ODF01 --> GF01
                {
                   tmpLylist[j].push({bm:bm,type:EnumType});
                }
             }   
         }
         
         ptmpLylist = ptmpLylist.concat(tmpLylist);   
     }      
    
     return ptmpLylist.concat(lylist);
}

//根据当前实体id号，得到路由
//
/*function GetLyListById_MAP(ID)
{
   
		var IDVal = parseInt(ID)
		var nodes = this.XmlDoc.selectNodes('Items/Item')
		
        //得到路由节点列表
        this.GetLyNodeById(IDVal);
        
		var LyStr = ""
		var LyStrPos = ""	
		var vFlg = false
		var vLyArray = new Array();
		
		for(var i = 0; i < this.lylist.length; i++)
		{
			var Ly = this.lylist[i]
			
	        vFlg = false;
	        LyStr = "";
	        LyStrPos = "";
			for(var j = 0; j < Ly.length; j ++)
			{
				var bFlg = true
				var tmpnode = Ly[j];
				
				var BMVal = $XML(tmpnode.selectNodes('BM')[0]);
				var vMBmList = tmpnode.selectNodes('MBmList');
				 
				var EnumTypeVal = $XML(tmpnode.selectNodes('EnumType')[0]);
			    
				 LyStrPos += GetGjsbTypeVal(parseInt(EnumTypeVal))
				 LyStrPos += ":"
				 LyStrPos += BMVal
				 if(j < Ly.length - 1)
				 {
				    LyStrPos += "|"
				 }
				
				
			    //如果该设备存在附属设备（OBD）
			    
				if(vMBmList[0].childNodes.length > 0)
				{
				    vFlg = true;

				    var vTempFlg = true
				    if(j < vMBmList[0].childNodes.length - 1)
				    {
				        var index =  parseInt($XML(vMBmList[0].childNodes[j + 1]))
				        var SjMBmList = nodes[index].selectNodes('SjMBmList') //从该pos的端子出来直接做了局向光纤
				        //var SjMBmListval = SjMBmList[0].text;
				        //var splitBm = SjMBmListval.split('|')
    				    
    				    
				        for(var y = 0;y < SjMBmList[0].childNodes.length; y++)
				        {
				            for(var x = 0;x < vMBmList[0].childNodes.length;x++)
				            {
				               if($XML(SjMBmList[0].childNodes[y]) == $XML(vMBmList[0].childNodes[x]))
				               {
				                 vTempFlg = false
				                 LyStrPos += "附属光分路器:"
				                 LyStrPos += $XML(vMBmList[0].childNodes[x])
				                 break;
				              }   
				            }  
				        }
				    }
				    if(vTempFlg)
				    {
				        for(var x = 0;x <  vMBmList[0].childNodes.length;x++)
				        {
				            LyStrPos += "附属光分路器:"
				            LyStrPos += $XML(vMBmList[0].childNodes[x])
				            if(x <  vMBmList[0].childNodes.length - 1)
				            {
				                LyStrPos += "_"
				            }
    				        
				        }
				     }
				    
				    if(j < vMBmList[0].childNodes.length - 1)
				    {
                        if(vTempFlg)
				        {
                            LyStrPos += "|"
                            LyStrPos += GetGjsbTypeVal(parseInt(EnumTypeVal))
				            LyStrPos += ":"
				            LyStrPos += BMVal
    				    }				    
					    LyStrPos += "|"
				    }
				}
			}
			var strVal = this.GetLyByLyMpos1(LyStrPos)
			vLyArray.push(strVal)
		}
		return vLyArray    
	
}
*/
function ConstructLyByZt_MAP(IDVal)
{
    var nodes = this.XmlDoc.selectNodes('Items/Item')
    //LyNodes = nodes[IDVal].selectNodes('LyList/Ly')	
    
	var vLyArray = new Array()
	for(var i = 0; i < this.lylist.length; i++)
    {
        var Ly = this.lylist[i]; //$XML(LyNodes[i])
		//var vsplit = Ly.split('|')
		var LyStr = ""	
		var tmpnode = Ly[0];
	    //var val =  parseInt(vsplit[0])
		var DevBMList = tmpnode.selectNodes('DevBM')
		var DevBMListVal = $XML(DevBMList[0])
		var vData = DevBMListVal.split('|')
		for(var x = 0; x < vData.length; x++)
		{
		     var childLyStr = ""
			 var cArray = getLyListByZt(nodes,vsplit,1); 
			 for(var n = 0; n <  cArray.length; n++)
			 {
			    childLyStr =  vData[x] + "|" + cArray[n];
			    if(LyStr != "")
			    {
			       LyStr += "+"
			    }
			    LyStr += childLyStr;
			 }
		}
	    vLyArray.push(LyStr);
    }
	return vLyArray
}

function getLyListByZt(nodes,vsplit,pos)
{
    if(pos == vsplit.length)
    {
        return "";
    }
    var returnArray = new Array();
    var val =  parseInt(vsplit[pos])
    
	var DevBMList = nodes[val].selectNodes('DevBM')
	var DevBMListVal = $XML(DevBMList[0])
	var vData = DevBMListVal.split('|')
	for(var x = 0; x < vData.length; x++)
	{
	    var childLyStr = ""
	    var cArray = getLyListByZt(nodes,vsplit,pos+1); 
	    if(cArray == "")
	    {
	       returnArray.push(vData[x])
	    }
	    else
	    {
	        for(var n = 0; n <  cArray.length; n++)
	        {
			     childLyStr =  vData[x] + "|" + cArray[n];  
			     returnArray.push(childLyStr)  
	        }
	    } 
	}
	return returnArray
}

function GetLyByLyMpos1_MAP(LyStrPos)
{
    var split = LyStrPos.split('|')
    var returnVal = ""
    for(var x = this.m_LyArrayList.length - 1; x >= 0;x--)
    {
       this.m_LyArrayList.pop();
    }
    for(var i = 0; i< split.length;i++)
    {
        var childArray = new Array()
        var childSplit = split[i].split('_')
        for(var j = 0;j < childSplit.length;j++)
        {
            childArray.push(childSplit[j]);
        }
          this.m_LyArrayList.push(childArray);          
    }
    
    var getLyArray = this.GetLyArrayList("",0);
    for(var j = 0; j < getLyArray.length; j++)
    {
        returnVal +=  getLyArray[j];
        if(j < getLyArray.length - 1)
        {
           returnVal +=  "+"
        }
    }
    return returnVal   
}

function GetLyArrayList_MAP(strLy,index)
{
    var returnLyArray =  new Array();
 
    for(var i = 0;i < this.m_LyArrayList[index].length + 1; i++)
    {
         var str = strLy;
         var lyArray = new Array();
         if(i == this.m_LyArrayList[index].length)
         {
              if(this.m_LyArrayList[index][0].indexOf("/MPOS") == -1)
              {
                  continue;
              }
              else if(index == 0)
              {
                  continue;
              }
              else if(index < this.m_LyArrayList.length - 1)
              {
                 if(this.m_LyArrayList[index + 1][0] != this.m_LyArrayList[index - 1][0])  //pos直接连局向光纤
                     continue
              }
         }
         else
         {
             if(index > 0)
             { 
                  str += "|" + this.m_LyArrayList[index][i]
             }
             else
             {
                str += this.m_LyArrayList[index][i]
             }
         }
         for(var j = index + 1;j < this.m_LyArrayList.length; j++)
         {
            var vFlg = true
            if(index > 0 && j == index + 1)
            {
                if(this.m_LyArrayList[j][0] == this.m_LyArrayList[index - 1][0] && i == this.m_LyArrayList[index].length)
                   vFlg = false
            }
            if(this.m_LyArrayList[j].length == 1 && this.m_LyArrayList[j][0].indexOf("/MPOS") < 0)
            {
                 if(vFlg)
                 {
                    str += "|" + this.m_LyArrayList[j][0];
                 }
            } 
            else
            {
               lyArray = GetLyArrayList(str,j);
               break;
            }
         }
         if(lyArray.length == 0)
         {
            var vSplitsLy = str.split('|');
            if(vSplitsLy.length < 2)
            {
                continue;
            }
            returnLyArray.push(str);
         }
         else
         {
             for(var n = 0;n < lyArray.length;n++)
             {
                  var vSplitsLy = lyArray[n].toString().split('|');
                  if(vSplitsLy.length < 2)
                  {
                      continue;
                  }
                  returnLyArray.push(lyArray[n]);
             }
         }

    }
    return returnLyArray;
}       

function IshasPos_MAP(id)
 {
     var returnVal = ""
      var IDVal = parseInt(id)
     var nodes = this.XmlDoc.selectNodes('Items/Item')
     var vMBmList = nodes[IDVal].selectNodes('MBmList')
     
     if(vMBmList[0].childNodes.length > 0)
     {
         returnVal = true
     }
     else
     {
         returnVal = false
     }
     return returnVal
 }


//得到编码列表 

function GetBmListByLy_MAP()
{
	
	var nodeid = this.m_idlist.id;
	var lyid   = this.m_idlist.lyid;
	
	var ly = this.objListLy[nodeid][lyid]; //得到当前路由列表
	var bmlist = "";
	for(var i = 0; i < ly.length; i++)
	{
	    bmlist += ly[i].bm
	    if(i < ly.length - 1)
	    {
	        bmlist += "|";
	    }
	}
	return bmlist;
	/*
	var index = ""
	var xh = ""
	var returnVal = ""
	if(this.m_precheck != "")
	{
	     var vData = this.m_precheck.id;
	     var splits = vData.split('-')
	     index = splits[0]
	     xh =  splits[1]
	}
	var split = this.m_LyArray[index].split('+')
	var LyList = split[xh]  
	var splitsbm = LyList.split('|')
	
	if(this.posAtFirsts)  //第一个设施是pos，这时取他的载体出逻辑图
	{
	   for(var i = 0; i< splitsbm.length; i++)
	   {
	      returnVal += splitsbm[i]
	      if(i<splitsbm.length - 1)
	      {
	         returnVal += "|"
	      } 
	   }
	   return returnVal
	}
	
	for(var i = 0; i< splitsbm.length; i++)
	{
	    var bm = splitsbm[i].split(':')
	    returnVal += bm[1]
	    if(i<splitsbm.length - 1)
	    {
	        returnVal += "|"
	    } 
	}
	
	return returnVal*/
}

 //查看路由详情
 
 
function LookLyDetial_MAP(dlg)
{
    var BMList = "";
    if(this.m_precheck == "")
    {
        CtnDlg.msg("请选择一条光路");
    }
    else
    {
        BMList = this.GetBmListByLy();
        
        var params = [this.grtype,BMList,this.qslay,this.zzlay,this.qxnum,0,this.bcfg,this.GetSelRes];  //grtype,bmlist,qsentlay,zzentlay,qx,bjump,bcfg,fun
        top.ExecuteATool(m_vt.FUN_SELJXGQ,params)
        
        dlg.close();
    }
}

//得到局向光纤结果列表

function GetSelRes_MAP(dlg)
{
     var Res = dlg.wnd.ReturnVal();
     if(Res)
     {
         if(window.resfun)    //当前窗口调用窗口的回调函数
         {
              dlg.close();              
              window.resfun(Res);
         }
     }
}


//选择路由列表中要查看的局向光纤
//nodeid  是lylist中的索引号     objListLy存储路由信息   lylist存储路由的节点信息
//lyid  是lylist[nodeid] 中的索引号

function check_MAP(nodeid,lyid,item)
{
    var bcheck = false;
   
    if(this.m_precheck == item)
    {
        if(item.checked == false)
        {
            bcheck = false;
            this.m_precheck = ""
            this.m_idlist = null;
        }
        else
        {
            bcheck = true;
        }    
        this.FlashLy(nodeid,bcheck)    
    } 
    else
    {
       if(this.m_precheck != "")
       {
           this.m_precheck.checked = false
           bcheck = false;
           this.FlashLy(this.m_idlist.id,bcheck) 
       }
       this.m_precheck = item
       this.m_idlist = {id:nodeid,lyid:lyid}
       bcheck = true
       this.FlashLy(nodeid,bcheck) 
    }          
  }
  
  //根据id闪烁路由
  
  function FlashLy_MAP(idlist,bcheck)
  {
        var vData = this.lylist[idlist];               //idlist.split('|')
        for(var i = 0;i < vData.length - 1;i++)
        {
            var vstr = $XML(vData[i].selectNodes("ID")[0]) + "-" + $XML(vData[i + 1].selectNodes("ID")[0])
            
            var vLin = this.drawPen.getObjById(vstr)
            if(vLin)
            {
               if(bcheck)
               {
                  vLin.setAttribute("strokecolor","red");
                  vLin.setAttribute("strokeweight","3px");
               }
               else
               {
                   vLin.setAttribute("strokecolor","blue");
                   vLin.setAttribute("strokeweight","2px");
               }  
            }
        }
  }

 //下一级逻辑图
 
 function GetNextLy_MAP(Id)
 {
     
     if(this.xmlArr.length == 0)
     {
         this.xmlArr.push(this.XmlDoc.xml); //将第一次出图的xml存入缓存
     }
       
       
       
      var node  = this.GetNodeById(Id);
      var layer = node.selectNodes('Layer'); 
      var LayerVal = parseInt($XML(layer[0]));
      
      
      this.zjNum = parseInt(LayerVal) +  parseInt(this.jmpn_nextly);
    
      var serverUrl = "_method=GetNextLy_Gr"
                               + "&ZjNum=" +escape(this.jmpn_nextly)
                               + "&id=" +escape(Id)
                               + "&GrType=" +escape(this.grtype);
                               
      var vRes = CtnTrans.getText("/main.ashx?", "post", serverUrl);
    
      this.xmlArr.push(vRes);         //将当前出图的xml存入缓存
      this.showLogicMap(vRes);
 }
 
 //返回上一级逻辑图(回退 )
 
 function BackPreLevel_MAP()
 {
    
     if(this.xmlArr.length > 1)
     {
     
         this.xmlArr.pop();
         
         var dispXml = this.xmlArr[this.xmlArr.length - 1];
         this.showLogicMap(dispXml);
     }
 }
 
 
 var list_obddz = null;
 
 function PosToGyhd_MAP(id)
 {
    var node = this.GetNodeById(id);
    
    //var bm     = $XML(node.selectNodes("BM")[0]);
    //var devtype = $XML(node.selectNodes("EnumType")[0]);
    var ListObd = "";

    var ListNode = node.selectNodes('MBmList')[0];
    for(var i = 0; i < ListNode.childNodes.length; i++)
    {
       ListObd += $XML(ListNode.childNodes[i]);
       if(i <  ListNode.childNodes.length - 1)
       {
           ListObd += "|";
       }  
    }
    //先选择一个OBD
    var obdxml = CtnTrans.getXml("/main.ashx?", "post", "_method=GetObdXml_Epon&obdlist=" + escape(ListObd));
    if (!CtnError.validate(obdxml))
    {
        CtnError.show();
        return;
    }
    var context = "<table><tr><td>光分路器:<select id='Sel_obd' onchange='changeobd()'>";
    var nodes = obdxml.selectNodes("items/item");
    for(var i = 0; i < nodes.length; i++)
    {
       var bm = $XML(nodes[i].selectNodes("bm")[0]);
       var mc = $XML(nodes[i].selectNodes("mc")[0]) || ""; 
       if(mc.length > 0) mc = "(" + mc + ")";
       
       if(i == 0)
       {   
           context += "<option value='"+bm+"||"+ mc +"' selected >" + bm + mc + "</option>"; 
       } 
       else
       {
           context += "<option value='"+bm+"||"+ mc +"'>" + bm + mc + "</option>"; 
       }    
    }
    context += "</select></td></tr><tr><td>";
    context += "<div>光分路器端子列表:</div><div id='list_obddz'></div></td></tr></table>";
    var params = {                        
                    title: "配置光分路器端子",
                    bmax: false,
                    bmodal: true,
                    width : 260,
                    height: 320,
                    arrbtn: [{text:"确  定", onClick:CfgOnu_call},{text:" 关  闭", onClick:function(dlg){dlg.close();}}]
                }
           
    var dlg = CtnDlg.show(context,params);  
    
    var obddzxml = CtnTrans.getText("/main.ashx?", "post", "_method=GetDzXmlByObd_Epon&obd=" + escape($XML(nodes[0].selectNodes("bm")[0])));
    if (!CtnError.validate(obddzxml))
    {
        CtnError.show();
        return;
    }
    
    list_obddz = new CtnListCtrl("list_obddz")   
    list_obddz.create("list_obddz");
    list_obddz.onCheck  = onCheck_obddz;
    list_obddz.reset();
    list_obddz.insertXml(obddzxml, 1);
   
    list_obddz.bscheck = true;
    list_obddz.show();
    
    var k = 0;
    while(true)
    {
        var obj = $("list_obddz_ckb_" + k);
        if(obj)
        {
           if(list_obddz.getCell(k,1).text != "空闲" || list_obddz.getCell(k,0).text == "0" || list_obddz.getCell(k,0).text == "0+")
           {
               obj.disabled="disabled";
           } 
        }
        else
        {
            break;
        }
        k++;
    }
    
    $("list_obddz").childNodes[0].childNodes[0].style.width = 220 + "px";
    current_selobd = null;
 }
 
 //选择了obd
 function changeobd()
 {
    var bm = $("Sel_obd").value.split('||')[0]
    var obddzxml = CtnTrans.getText("/main.ashx?", "post", "_method=GetDzXmlByObd_Epon&obd=" + escape(bm));
    if (!CtnError.validate(obddzxml))
    {
        CtnError.show();
        return;
    }
    list_obddz = new CtnListCtrl("list_obddz")   
    list_obddz.create("list_obddz");
    list_obddz.onCheck  = onCheck_obddz;
    list_obddz.reset();
    list_obddz.insertXml(obddzxml, 1);
    list_obddz.bscheck = true;
    
    list_obddz.show();
    
    var k = 0;
    while(true)
    {
        var obj = $("list_obddz_ckb_" + k);
        
        if(obj)
        {
           if(list_obddz.getCell(k,1).text != "空闲" || list_obddz.getCell(k,0).text == "0" || list_obddz.getCell(k,0).text == "0+")
           {
               obj.disabled="disabled";
           }
        }
        else
        {
            break;
        }
        k++;
    }
    $("list_obddz").childNodes[0].childNodes[0].style.width = 220 + "px";
    
    current_selobd = null;
    
 }
 
 var current_selobd = null;
 function onCheck_obddz(rowno,checked)
 {
    if(checked)
    {
        current_selobd = rowno;
    }
 }
 //配置
 function CfgOnu_call(dlg)
 {
    //根据所选OBD得到ONU信息
    if(current_selobd == null)
    {
       alert("请选择光分路器端子");
       return; 
    }
    var obddz = list_obddz.getCell(current_selobd,0).text;
    var obdbmmc = $("Sel_obd").value;
    var splitobd = obdbmmc.split('||');
    var obdbm = splitobd[0];
    var obdmc = splitobd[1];
    dlg.close();
    
    var serverUrl = "_method=GetOnuByObd_Epon&obd=" +escape(obdbm);                           
    var xml = CtnTrans.getXml("/main.ashx?", "post", serverUrl);
    if (!CtnError.validate(xml))
    {
        CtnError.show();
        return;
    }
    
    var nodes = xml.selectNodes("item");
    if(nodes.length > 0)
    {
       var bm = $XML(nodes[0].selectNodes("bm")[0])
       var mc = $XML(nodes[0].selectNodes("mc")[0]) || "";
       var khmc = $XML(nodes[0].selectNodes("khmc")[0]) || ""; 
       var zxbh = $XML(nodes[0].selectNodes("zxbh")[0]) || "";
       var wz = $XML(nodes[0].selectNodes("wz")[0]) || "";
       var bz = $XML(nodes[0].selectNodes("bz")[0]) || ""; 
      
       var context = "<table><tr>"
                  + "<td>客户名称:</td><td><input type='text' value='' id='khmc_text' /></td></tr>"   
                  + "<tr><td>专线编号:</td><td><input type='text' value='' id='zxbh_text' /></td></tr>"   
                  + "<tr><td>安装地址:</td><td><input type='text' value='' id='wz_text' /></td></tr>"   
                  + "<tr><td>备注:</td><td><input type='text' value='' id='bz_text' /></td></tr>";   
   
       var params = {                        
                    title: "配置光用户点属性",
                    bmax: false,
                    bmodal: true,
                    width : 260,
                    height: 200,
                    arrbtn: [{text:"确  定", onClick:function(dlg){GetOnuLy_call(dlg,bm,mc,obdbm,obdmc,obddz);}},{text:" 关  闭", onClick:function(dlg){dlg.close();}}]
                }
           
       var dlg = CtnDlg.show(context,params);  
    }
    
 }
 
 
 function GetOnuLy_call(dlg,bm,mc,obdbm,obdmc,obddz)
 {
    //返回配置界面  onu默认为0端子
    var Res = "";
    
    Res = "<?xml version='1.0' encoding='gb2312' ?><items>"
        + "<item>"
        + "<ly><adtype>9</adtype><adbm>"+obdbm+"</adbm><admc>"+obdmc+"</admc><adkh></adkh><addz>"+obddz+"</addz><adglmc></adglmc><adglqx></adglqx>"
        + "<bdtype>10</bdtype><bdbm>"+bm+"</bdbm><bdmc>"+mc+"</bdmc><bdkh></bdkh><bddz>0</bddz><bdglmc></bdglmc><bdglqx>3</bdglqx></ly></item></items>";

    
    var onuAtt = "";
    var khmc = $("khmc_text").value;
    var zxbh = $("zxbh_text").value;
    var wz   = $("wz_text").value;
    var bz   = $("bz_text").value;
    
    onuAtt = "<?xml version='1.0' encoding='gb2312' ?><items>"
          + "<item>"
          + "<bm>" + bm + "</bm>"
          + "<mc>" + mc + "</mc>"
          + "<khmc>" + khmc + "</khmc>"
          + "<zxbh>" + zxbh + "</zxbh>"
          + "<azdz>" + wz + "</azdz>"
          + "<bz>" + bz + "</bz>"
          + "</item></items>";
    
    
    Res += "||" + onuAtt;
    
    if(window.resfun)    //当前窗口调用窗口的回调函数    
    {
         dlg.close();              
         window.resfun(Res);
    }
 }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////